﻿using ShanNiang.Service.Constants;
using ShanNiang.Service.Enumerate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShanNiang.Service.Scaner
{
    public class CodeEventArgs : ScanerEventArgs
    {
        public CodeEventArgs(string scannedText) : base(scannedText)
        {
            if (CommonData.Regex_BottleCode.IsMatch(scannedText))
            {
                CodeType = CodeType.BottleCode;
                Code = CommonData.Regex_BottleCode.Match(scannedText).Value;
            }
            else if (CommonData.Regex_BoxCode.IsMatch(scannedText))
            {
                CodeType = CodeType.BoxCode;
                Code = CommonData.Regex_BoxCode.Match(scannedText).Value;
            }
            else if (CommonData.Regex_PalletCode.IsMatch(scannedText))
            {
                CodeType = CodeType.PalletCode;
                Code = CommonData.Regex_PalletCode.Match(scannedText).Value;
            }
            else if (CommonData.Regex_Barcode.IsMatch(scannedText))
            {
                CodeType = CodeType.Barcode;
                Code = CommonData.Regex_Barcode.Match(scannedText).Value;
            }
            else 
            {
                CodeType = CodeType.Unknown;
                Code = "";
            }
        }

        public CodeType CodeType { get; private set; }
        public string Code { get; private set; }

    }
}
